import { useState, useEffect } from "react";
import { Form, Select, message } from "antd";
import { CommonModal } from "@/views/components/CommonModal";
import SubTitle from "@/pages/OrderModule/common/components/SubTitle";
import GoPay from "./goPay";
import { cashpaymentMethod, makeinventoryComplete } from "../service";

const CompleteCountModal = ({
	visible,
	fetchList,
	selectedKeys,
	handleCompleteOk,
	printExpressList,
	selectedRows,
	data,
	handleCancel
}) => {
	const [form] = Form.useForm();
	const [addVisible, addSetVisible] = useState(false);
	const [totalPrice, setTotalPrice] = useState(0);
	const [totalCount, setTotalCount] = useState(0);
	// const [data, setData] = useState({});

	useEffect(() => {
		// makeinventoryCompleteData();
		const totalInventoryPrice = selectedRows.reduce(
			(sum, item) => sum + Number(item.inventoryPrice ? item.inventoryPrice : 0),
			0
		);
		const totalInventoryCount = selectedRows.reduce(
			(sum, item) => sum + Number(item.completeWaitCount ? item.completeWaitCount : 0),
			0
		);
		setTotalPrice(totalInventoryPrice);
		setTotalCount(totalInventoryCount);
		if (visible) {
			form.resetFields();
		}
	}, [visible]);
	const CheckStockAndNoteProps = {
		addVisible,
		selectedKeys,
		data,
		totalCount,
		printExpressList,
		fetchList,
		totalPrice,
		selectedRows,
		handleOk(data) {
			console.log(data, "data");
			handleCompleteOk(data);
		},
		// 支付关闭
		handleCancel() {
			onCancel(); //关闭当前页
			addSetVisible(0);
		}
	};
	const onOk = () => {
		addSetVisible(true);
	};
	const onCancel = () => {
		handleCancel();
		form.resetFields();
	};

	return (
		<CommonModal
			title={{ title: "完成清点" }}
			visible={true}
			onOk={onOk}
			okText="去支付"
			onCancel={onCancel}
			width={"333px"}
			minHeight="150px"
		>
			<SubTitle symbol as="s2" title={`清点详情`} wrapStyle={{ marginBottom: 16 }} />
			<Form form={form} name="mark-unuaual-modal">
				<Form.Item label="本次清点商品数：" style={{ marginLeft: 8 }}>
					<div>{data.count}</div>
				</Form.Item>
				<Form.Item label="采购总价：" style={{ marginLeft: 8 }}>
					<div style={{ color: "rgba(240, 61, 41, 1)" }}>￥{data.meetTotalAmount}</div>
				</Form.Item>
				{/* <Form.Item label="应付账期金额：" style={{ marginLeft: 8 }}>
					<div style={{ color: "rgba(240, 61, 41, 1)" }}>￥{data.creditTotalAmount}</div>
				</Form.Item>
				<Form.Item label="应付金额：" style={{ marginLeft: 8 }}>
					<div style={{ color: "rgba(240, 61, 41, 1)" }}>￥{data.balanceTotalAmount}</div>
				</Form.Item> */}
			</Form>
			{addVisible == true && <GoPay {...CheckStockAndNoteProps} />}
		</CommonModal>
	);
};

export default CompleteCountModal;
